<?php  if ( ! defined('CentPHP')) exit( "Disallow to access direct!" );
/*
    |====================================================|
	|  CentPHP                                           |
	|----------------------------------------------------|
	|  package      lib/kernel/Common.php                |
	|  auther       Boyu Sun                             |
	|  copyright    Copyright (c) 2008, sunboyu.cn       |
	|  license      freebsd-license                      |
	|  link         www.sunboyu.cn                       |
	|  version      Version 0.1                          |
	|====================================================|
*/


/*
    +-------------------------------------------------------------------
	| function new_class( $classname )
	|
	| @param   @classname
	| @return  @object
	+-------------------------------------------------------------------
*/

function &new_class( $classname , $method = true )
{
	static $object;
	if(isset( $object[$classname] ))
	{
		return $object[$classname];
	}
	if(false==$method)
	{
		$object[$classname] = true;
		//return $object[$classname];
	}
	if(file_exists(LIBPATH.'/Class.'.$classname.EXT))
	{
		require_once(LIBPATH.'/Class.'.$classname.EXT);
		$object[$classname] = & new $classname();
	}
	else if(file_exists(CTPATH.'/'.$classname.EXT))
	{
		require_once(CTPATH.'/'.$classname.EXT);
		$object[$classname] = & new $classname();
	}
	else if(file_exists(ULIBPATH.'/'.$classname.EXT))
	{
		require_once(ULIBPATH.'/'.$classname.EXT);
		$object[$classname] = & new $classname();
	}
	else
	{
		$object[$classname] = false;
	}
	return $object[$classname];
}

/*
    +-------------------------------------------------------------------
	| function load_config( $configname , $item )
	|
	| @param   @configname
	| @param   @item
	| @return  @array
	+-------------------------------------------------------------------
*/

function &load_config( $configname , $item = false , $method = 'return' )
{
	$configs = array();
	
	if(file_exists(CONFIGPATH.'/Config.'.$configname.EXT))
	{
		require_once(CONFIGPATH.'/Config.'.$configname.EXT);
		$configs = $config;
	}
	else
	{
		die('Config file '.$configname.' not exists!');
	}
	if($item)
	{
		$configs = $configs[$item];
	}
	if($method=='define')
	{
	    foreach( $configs as $key => $value )
		{
		    define( $key , $value );
		}
	}
	return $configs;
}
/*
    +-------------------------------------------------------------------
	| function GetSqlString( $string , $type )
	|
	| @param   @string
	| @param   @type
	| @return  @string
	+-------------------------------------------------------------------
*/

function GetSqlString( $string , $type = "text" )
{
	if ( get_magic_quotes_gpc() )
	{
		$string = stripslashes($string);
	}
	else
	{
		$string = mysql_real_escape_string($string);
	}
	
    switch($type)
	{
	    case 'text':
		    return "'".$string."'";
		break;
		case "int";
		    return intval($string);
		break;
	}
}
?>